predictZF = function(plik){
  library(xts)
  dane = read.csv(plik, header = F, colClasses = c("character", "numeric"))
  dane = xts(dane[, 2], as.Date(dane[, 1], "%Y%m%d"))
  T = length(dane)
  # returns = diff(log(dane)) median(returns[3:11])
  returns = diff(dane)/lag(dane)
  forecast = array(NA, T)
  for (i in 12:T){
    ret = 1.03*median(returns[3:11]) - 0.03*as.numeric(returns[i-1])
    forecast[i] = dane[i-1] * (1 + ret)
  }
  return(cbind(dane, forecast))
}

d1 = "ZF_2009_2010_M.csv"
f1 = predictZF(d1)
RWE1 = sum(abs(diff(f1[, 1]))[13:24])
FE1 = sum(abs(f1[13:24, 1]-f1[13:24, 2]))
print(RWE1)
print(FE1)
print(FE1/RWE1)
plot(f1[, 1], type = "l")
lines(f1[, 2], col = "red")
